<template>
  <div class="login-container">
    <div class="login-box">
      <h2 class="title">Welcome Back</h2>
      <form @submit.prevent="handleSubmit">
        <div class="input-group">
          <label>Username</label>
          <input type="text" v-model="form.user_name" placeholder="Enter your username" required />
        </div>
        <div class="input-group">
          <label>Password</label>
          <input
            type="password"
            v-model="form.password"
            placeholder="Enter your password"
            required
          />
        </div>
        <button type="submit" class="login-btn">Sign In</button>
      </form>
      <div class="additional-links">
        <a href="#">Forgot Password?</a>
        <!-- <a href="#">Create Account</a> -->
        <router-link to="/register">Create Account</router-link>
      </div>
    </div>
  </div>
</template>

<script setup>
import { reactive } from 'vue'
import { loginApi } from '../api/index.ts'

const form = reactive({
  user_name: '',
  password: '',
})

const handleSubmit = () => {
  // 处理登录逻辑
  console.log('Form submitted', form)
  loginApi(form.user_name, form.password).then((res) => {
    console.log(res)
    alert(res.data.message)
  })
}
</script>

<style scoped>
.login-container {
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  background-image: url('/bg.jpg');
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  /* padding: 20px; */
}

.login-box {
  background: rgba(255, 255, 255, 0.95);
  padding: 2rem;
  border-radius: 15px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
  width: 100%;
  max-width: 400px;
  backdrop-filter: blur(10px);
}

.title {
  text-align: center;
  color: #2c3e50;
  margin-bottom: 2rem;
}

.input-group {
  margin-bottom: 1.5rem;
}

label {
  display: block;
  margin-bottom: 0.5rem;
  color: #4a5568;
  font-weight: 500;
}

input {
  width: 100%;
  padding: 0.8rem;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  font-size: 1rem;
  transition: border-color 0.3s ease;
  box-sizing: border-box;
}

input:focus {
  outline: none;
  border-color: #4299e1;
  box-shadow: 0 0 0 3px rgba(66, 153, 225, 0.2);
}

.login-btn {
  width: 100%;
  padding: 1rem;
  background: linear-gradient(135deg, #4299e1, #3182ce);
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.3s ease;
}

.login-btn:hover {
  opacity: 0.9;
}

.additional-links {
  margin-top: 1.5rem;
  display: flex;
  justify-content: space-between;
  font-size: 0.9rem;
}

.additional-links a {
  color: #4a5568;
  text-decoration: none;
  transition: color 0.3s ease;
}

.additional-links a:hover {
  color: #4299e1;
}

@media (max-width: 480px) {
  .login-box {
    padding: 1.5rem;
    margin: 0 15px;
  }

  input {
    padding: 0.7rem;
  }

  .login-btn {
    padding: 0.8rem;
  }
}
</style>
